<?php
// +----------------------------------------------------------------------
// | BhAdmin [ BhAdmin匠心打造，我们相信，每个伟大的软件都有一个伟大的故事 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020~2023 https://www.bhadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed BhAdmin并不是自由软件，未经许可不能去掉BhAdmin相关版权
// +----------------------------------------------------------------------
// | Author: BAIHU  <admin@bhadmin.cn>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\admin\logic\UserLogic;
use support\Backend\BackendController;
use support\Container;
use support\Response;

/**
 * 后台用户管理
 */
class UserController extends BackendController
{


    public function __construct()
    {
        parent::__construct();
        $this->logic = Container::get(UserLogic::class);

    }

    /**
     * 添加或编辑
     * @return Response
     */
    public function edit(): Response
    {
        $data = request()->post();
        if (!empty($data['id']) && $data['id'] == 1 && ($this->userId != 1)) return error(-1, '非法操作');
        return success($this->logic->edit());
    }

    /**
     * 获取用户的角色
     * @since 2020/11/19
     */
    public function getRoles(): Response
    {
        return success($this->logic->getRoles());
    }

    /**
     * 编辑用户角色
     * @since 2020/11/19
     */
    public function updateRoles(): Response
    {
        return success($this->logic->updateRoles());
    }

    /**
     * 修改指定用户密码
     * @since 2020/11/19
     */
    public function updatePwd(): Response
    {
        return success($this->logic->restartPwd());
    }

}
